﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using SpaceMan.Physics;

namespace SpaceMan
{
    class C_GameCamera
    {
        
        public C_GameCamera(Vector2 Position, float scale, bool isMainGameCamera)
        {
            Object = new PHY_Base(Position, 1, 1,false, null, null, this.GetType().Name);
            this.scale = scale;
            this.isMainGameCamera = isMainGameCamera;
        }
        public void Update(Vector2 Position, float Zoom, float Rotation)
        {       
            //Object.currentState.Pos = Position;
            Object.Addforce(new Vector2(0, 0));
            this.Zoom = Zoom;
            this.Rotation = Rotation;
            
            Object.ParentMe(Object, "C_Player0", false);
            
        }

        public void UpdateConfinePosition()
        {
            if (isMainGameCamera)
            {
                if (Object.children.Count > 0)
                {
                    S_Global.screenPosition = Object.currentState.Pos * scale;
                    S_Global.ZoomFactor = this.Zoom;
                    Object.children[0].Confine(Object.currentState.Pos * scale, S_Global.CurrrentlyVisibleWorld().Width, S_Global.CurrrentlyVisibleWorld().Height);
                }
            }
        }

        public Rectangle getDrawSpace(GraphicsDevice gd)
        {
            return new Rectangle((int)(Object.currentState.Pos.X * scale), (int)(Object.currentState.Pos.Y * scale), (int)(gd.Viewport.Width / Zoom), (int)(gd.Viewport.Height / Zoom));
        }

        PHY_Base Object;
        float Rotation;
        float Zoom;
        float scale;
        bool isMainGameCamera;
        public Matrix TransformMatrix
        {
            get
            {
                return Matrix.CreateRotationZ(Rotation) * Matrix.CreateScale(Zoom) *
                       Matrix.CreateTranslation(-Object.currentState.Pos.X * Zoom * scale, -Object.currentState.Pos.Y * Zoom * scale, 0);
            }
        }
    }
}
